import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '帝可得', icon: 'el-icon-s-home' }
    }]
  },
  // {
  //   path: '/example',
  //   component: Layout,
  //   redirect: '/example/table',
  //   name: 'Example',
  //   meta: { title: '工单管理', icon: 'el-icon-document' },
  //   children: [
  //     {
  //       path: 'table',
  //       name: 'Table',
  //       component: () => import('@/views/table/index'),
  //       meta: { title: '运营工单' }
  //     },
  //     {
  //       path: 'tree',
  //       name: 'Tree',
  //       component: () => import('@/views/tree/index'),
  //       meta: { title: '运维工单' }
  //     }
  //   ]
  // },
  {
    path: '/example',
    component: Layout,
    redirect: '/example/table',
    name: 'Example',
    meta: { title: '工单管理', icon: 'el-icon-document' },
    children: [
      {
        path: 'table',
        name: 'Table',
        component: () => import('@/views/table/index'),
        meta: { title: '运营工单' }
      },
      {
        path: 'tree',
        name: 'Tree',
        component: () => import('@/views/tree/index'),
        meta: { title: '运维工单' }
      }
    ]
  },
  // {
  //   path: '/form',
  //   component: Layout,
  //   redirect: '/example/table',
  //   name: 'Example',
  //   meta: { title: '点位管理', icon: 'el-icon-map-location' },
  //   children: [
  //     {
  //       path: 'index',
  //       name: 'Form',
  //       component: () => import('@/views/form/index'),
  //       meta: { title: '区域管理' }
  //     },
  //     {
  //       path: 'pointLocation',
  //       name: 'pointLocation',
  //       component: () => import('@/views/form/pointLocation'),
  //       meta: { title: '点位管理' }
  //     },
  //     {
  //       path: 'officialPartner',
  //       name: 'officialPartner',
  //       component: () => import('@/views/form/officialPartner'),
  //       meta: { title: '合作商管理' }
  //     }
  //   ]
  // },
  {
    path: '/form',
    component: Layout,
    redirect: '/example/table',
    name: 'Example',
    meta: { title: '定位管理', icon: 'el-icon-map-location' },
    children: [
      {
        path: 'index',
        name: 'Form',
        component: () => import('@/views/form/index'),
        meta: { title: '区域管理' }
      },
      {
        path: 'OfficialPartner',
        name: 'Form',
        component: () => import('@/views/form/OfficialPartner'),
        meta: { title: '定位管理' }
      },
      {
        path: 'PointLocation',
        name: 'Form',
        component: () => import('@/views/form/PointLocation'),
        meta: { title: '合作商管理' }
      }
    ]
  },

  // {
  //   path: '/nested',
  //   component: Layout,
  //   redirect: '/nested/menu1',
  //   name: 'Nested',
  //   meta: {
  //     title: '设备管理',
  //     icon: 'el-icon-setting'
  //   },
  //   children: [
  //     {
  //       path: 'menu1-1',
  //       component: () => import('@/views/nested/menu1/menu1-1'),
  //       name: 'Menu1-1',
  //       meta: { title: '设备管理' }
  //     },
  //     {
  //       path: 'menu1-2',
  //       component: () => import('@/views/nested/menu1/menu1-2'),
  //       name: 'Menu1-2',
  //       meta: { title: '设备状态' }
  //     },
  //     {
  //       path: 'menu1-3',
  //       component: () => import('@/views/nested/menu1/menu1-3'),
  //       name: 'Menu1-3',
  //       meta: { title: '设备类型管理' }
  //     }
  //   ]
  // },
  {
    path: '/nested',
    component: Layout,
    redirect: '/nested/menu1',
    name: 'Nested',
    meta: {
      title: '设备管理',
      icon: 'el-icon-setting'
    },
    children: [
      {
        path: 'menu1-1',
        component: () => import('@/views/nested/menu1/menu1-1'), // Parent router-view
        name: 'Menu1',
        meta: { title: '设备管理' }

      },
      {
        path: 'menu1-2',
        component: () => import('@/views/nested/menu1/menu1-2'),
        name: 'Menu2',
        meta: { title: '设备状态' }
      },
      {
        path: 'menu1-3',
        component: () => import('@/views/nested/menu1/menu1-3'),
        name: 'Menu2',
        meta: { title: '设备类型管理' }
      }
    ]
  },

  // {
  //   path: '/management',
  //   component: Layout,
  //   redirect: 'management/personnellist',
  //   name: 'Nested',
  //   meta: {
  //     title: '人员管理',
  //     icon: 'el-icon-s-check'
  //   },
  //   children: [
  //     {
  //       path: 'personnellist',
  //       component: () => import('@/views/personnel'),
  //       name: 'personnellist',
  //       meta: { title: '人员列表' }
  //     },
  //     {
  //       path: 'productivity',
  //       component: () => import('@/views/personnel/statistics'),
  //       name: 'productivity',
  //       meta: { title: '人效统计' }
  //     },
  //     {
  //       path: 'workload',
  //       component: () => import('@/views/personnel/workload'),
  //       name: 'workload',
  //       meta: { title: '工作量列表' }
  //     }
  //   ]
  // },
  {
    path: '/personnel',
    component: Layout,
    redirect: '/personnel/personnelList',
    name: 'personnel',
    meta: {
      title: '人员管理',
      icon: 'el-icon-s-check'
    },
    children: [
      {
        path: 'personnelList',
        component: () => import('@/views/personnel'), // Parent router-view
        name: 'personnelList',
        meta: { title: '人员列表' }

      },
      {
        path: 'statistics',
        component: () => import('@/views/personnel/statistics'),
        name: 'Menu2',
        meta: { title: '人效统计' }
      },
      {
        path: 'workloadLIst',
        component: () => import('@/views/personnel/workload'),
        name: 'workloadLIst',
        meta: { title: '工作量列表' }
      }
    ]
  },
  // {
  //   path: '/commodity',
  //   component: Layout,
  //   redirect: 'commodity/mold',
  //   name: 'commodity',
  //   meta: {
  //     title: '商品管理',
  //     icon: 'el-icon-files'
  //   },
  //   children: [
  //     {
  //       path: 'mold',
  //       component: () => import('@/views/commodity/mold'),
  //       name: 'mold',
  //       meta: { title: '商品类型' }
  //     },
  //     {
  //       path: 'Administrator',
  //       component: () => import('@/views/commodity'),
  //       name: 'Administrator',
  //       meta: { title: '商品管理' }
  //     }
  //   ]
  // },
  {
    path: '/commodity',
    component: Layout,
    redirect: '/commodity/commodityMold',
    name: 'commodity',
    meta: {
      title: '商品管理',
      icon: 'el-icon-files'
    },
    children: [
      {
        path: 'commodityMold',
        component: () => import('@/views/commodity/mold'), // Parent router-view
        name: 'commodityMold',
        meta: { title: '商品类型' }

      },
      {
        path: 'Administrator',
        component: () => import('@/views/commodity'),
        name: 'Administrator',
        meta: { title: '商品管理' }
      }
    ]
  },
  // {
  //   path: '/strategy',
  //   component: Layout,
  //   redirect: 'strategy',
  //   children: [{
  //     path: 'strategy',
  //     name: 'strategy',
  //     component: () => import('@/views/strategy'),
  //     meta: { title: '策略管理', icon: 'el-icon-sunny' }
  //   }]
  // },
  {
    path: '/strategy',
    component: Layout,
    redirect: 'strategy',
    children: [
      {
        path: 'strategy',
        name: 'strategy',
        component: () => import('@/views/strategy'),
        meta: { title: '策略管理', icon: 'el-icon-sunny' }
      }
    ]
  },
  // {
  //   path: '/orderForm',
  //   component: Layout,
  //   redirect: '/orderForm',
  //   children: [{
  //     path: 'orderForm',
  //     name: 'orderForm',
  //     component: () => import('@/views/orderForm'),
  //     meta: { title: '订单管理', icon: 'el-icon-s-claim' }
  //   }]
  // },
  {
    path: '/orderForm',
    component: Layout,
    redirect: 'orderForm',
    children: [
      {
        path: 'orderForm',
        name: 'orderForm',
        component: () => import('@/views/orderForm'),
        meta: { title: '订单管理', icon: 'el-icon-s-claim' }
      }
    ]
  },
  {
    path: '/bill',
    component: Layout,
    redirect: '/bill',
    children: [{
      path: 'bill',
      name: 'bill',
      component: () => import('@/views/bill'),
      meta: { title: '对账统计', icon: 'el-icon-s-data' }
    }]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
